<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>商品分类</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
    <link rel="stylesheet" type="text/css" href="../css/swiper.min.css" />
    <link rel="stylesheet" type="text/css" href="../css/layer.css" />
    <link rel="stylesheet" type="text/css" href="../css/mdw.css" />
    <script type="text/javascript" src="../script/api.js"></script>
    <script type="text/javascript" src="../script/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="../script/swiper.min.js"></script>
    <script type="text/javascript" src="../script/mobile.js"></script>
    <script type="text/javascript" src="../script/layer.js"></script>
    <script type="text/javascript" src="../script/mdw.js"></script>
    <script type="text/javascript" src="../script/jumpPage.js"></script>

</head>
<body>
    <header class="header classifyHeader">
        <div class="backPrevPage" onclick="historyBack()"></div>
        <div class="classifyType">
            <div class="comtype on">种草圈<div class="pageOn"></div></div>
            <div class="comtype" >折扣圈<div class="pageOn"></div></div>
        </div>
        <div class="headerRight" onclick="openWin('classify_search','classify_search.html')"><i></i></div>
    </header>
    <section class="classifyPage HTML_BOX">
        <ul class="classifType2 plr">
            
        </ul>
        
        <div class="pageHide dn">暂无数据..</div>
        <div class="bg-eee" style="border-bottom:.2rem solid #EEE ; "></div>
        <ul class="comList plr">
            <!-- <li onclick="openWin('community_details','community_details.html')>
                <img class="comImg" src="../image/com_img.png" />
                <div class="comTitle">超新鲜蔬菜、水果，吃了健康养生...</div>
                <div class="comUser plr">
                    <div class="userBox1">
                        <img class="userTx" src="../image/tx.png" />
                        <div class="name">王多多王多多</div>
                    </div>
                    <div class="comCount">
                        <i></i>2508
                    </div>
                </div>
            </li> -->
        </ul>
    </section>
</section>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript">
    var page =1;
    var type =1;
    var commtype_id = 0;
    var ifpage = true;
    $(function(){
        var header = $(".header").height();
        var classifType2 = $(".classifType2").height();
        var navigation = $(".navigation").height();
        var marginBox = $(".marginBox").height();
        
        var body = window.screen.availHeight;
        var i = header + classifType2 + navigation + marginBox;
        var c = body-i;
        $(".classifyList").css("height",c);
    })
    $(".comtype").click(function(){
        $(".comtype").removeClass("on");
        $(this).addClass("on");
        type = Number($(this).index())+1;
        page=1;
        getList();
    });
    $(".classifType2 li").click(function(){
        $(".classifType2 li").removeClass("on");
        $(this).addClass("on");
    })
    $(".classifType2 li").click(function(){
        $(".classifType2 li").removeClass("on");
        $(this).addClass("on");
        var h = '<span></span>'+$(this).text()+'<span></span>'
        $(".left_title").html(h);
    })
    apiready = function(){
        api.setStatusBarStyle({
            color: '#fff',//设置APP状态栏背景色
            style: 'dark'
        });
        api.addEventListener({
            name: 'scrolltobottom',
            extra: {
                 threshold: 10
            }
         }, function(ret, err) {
             //页码+1，继续请求数据
             if(ifpage){
                page++;
                    ready();
             }
             
        });
        ready();
    };
    function ready(){
        $api.fixStatusBar($api.dom('header'));
        getAjax(Interface.commtype,{},function(res){
            $(".classifType2").empty();
             $.each(res.data,function(i,item){
                    var html ='';
                    if(i==0){
                        html ='<li onclick="getType2(this,'+item.id+')" class="on">'+item.title+'</li>';
                        commtype_id = item.id;
                        getList();
                        var h = '<span></span>'+item.title+'<span></span>'
                         $(".left_title").html(h);
                    }else{
                        html ='<li onclick="getType2(this,'+item.id+')">'+item.title+'</li>';
                    }
                $(".classifType2").append(html);
             })
        },function(res,err){})
    }
    function getList(){
        pop.loading();
        var p = {type:type,page:page,commtype_id:commtype_id};
        getAjax(Interface.comm_list,p,function(res){
            console.log(JSON.stringify(res));
            pop.close();
            var list = res.data;
            if(page==1){
                $(".comList").empty();
            }
            if(list){
                $(".pageHide").addClass("dn");ifpage=true;
                $.each(list,function(i,item){
                    var html ='<li onclick="go_details('+item.id+')">';
                            html+='<div class="comImg"><img src="'+getImg(item.icon)+'" /></div>';
                            if(cnen == 2){
                                item.title = item.egname;
                            }
                            html+='<div class="comTitle"><span>'+item.title+'</span></div>';
                            html+='<div class="comUser plr">';
                                html+='<div class="userBox1">';
                                    html+='<img class="userTx" src="'+getImg(item.uicon)+'" />';
                                    html+='<div class="name">'+item.username+'</div>';
                                html+='</div>';
                                html+='<div class="comCount">';
                                    html+='<i></i>'+item.view_num;
                                html+='</div>';
                            html+='</div>';
                        html+='</li>';
                    $(".comList").append(html);
                })
                if(list.length<10){
                    $(".getPage").hide();
                }
            }else{
                 ifpage=false;
                 if(page==1){$(".pageHide").removeClass("dn");}
            }
        },function(res,err){})
    }

    $(".getPage").click(function(){
        page++;
        getList();
    })

    function getType2(dom,id){
        $(".classifType2 li").removeClass("on");
        $(dom).addClass("on");
        commtype_id = id;
        page=1;
        getList();
    }

    function go_details(id){
        openWin('community_details','community_details.html',{id:id});
    }
</script>
<script type="text/javascript">
    function ifCnAndEn(){
        if(cnen==2){
            $(".comtype").eq(0).html('Want to buy');
            $(".comtype").eq(1).html('Discount');
        }
    }
</script>
</html>